<template>
    <div class="template-form-Lu">
      <a-modal
        :visible="applicationFormVisible"
        title=""
        :maskClosable="false"
        :closable="true"
        :destroyOnClose="true"
        width="100%"
        :dialog-style="{ margin: '0 auto'}"
        wrapClassName="form-modal-Lu"
        @cancel="closeVisible"
        >
        <template slot="footer">
          <a-button v-if="showFooter == false" key="back" @click="saveTable('保存')">
            保存
          </a-button>
          <a-button :loading="loading" v-if="showFooter == false" class="blue-btn" @click="subTable('提交')">
            提交
          </a-button>
          <a-button v-if="showFooter == false&&linkName !== '申请'" class="red-btn" @click="returnClick">
            退回
          </a-button>
          <a-button v-if="showFooter == true" @click="closeVisible" class="blue-btn">关闭</a-button>
          <a-button v-if="showFooter == true&&linkName=='加班办理'" @click="subTable('提交')" class="blue-btn">确认加班值班</a-button>
          <a-button v-if="showFooter == true&&linkName=='数据修订'" @click="editTable" class="blue-btn">确认修订</a-button>
        </template>
        <a-form :form="cform" ref="form">
          <a-tabs type="card" v-if="applicationFormVisible" @change="callback">
            <a-tab-pane key="1" tab="审批表">
              <div class="print-div-shu" id="printTest">
                <h1 class="h1-page">自治区食品药品审评查验中心<br/>干部职工加班值班登记表</h1>
                <table border="1" cellspacing="0" class="table-Lu jbzb-table">
                  <tr v-if="linkName !== '申请'">
                    <th>填报部门</th>
                    <td v-if="linkName=='数据修订'" colspan="2">
                      <a-input
                        v-model="form.fbm"
                        class="">
                      </a-input>
                    </td>
                    <td v-else colspan="2">
                      {{ form.fbm }}
                    </td>
                    <th>申请时间</th>
                    <td v-if="linkName=='数据修订'" colspan="2" class="">
                      <a-date-picker
                        show-time
                        placeholder="请选择报送时间"
                        v-model="form.fjbzbsqrq"
                        @change="timeChang($event,'fjbzbsqrq')"
                        class=""
                        style="width:220px;"/>
                    </td>
                    <td v-else colspan="2" class="">
                      {{ form.fjbzbsqrq }}
                    </td>
                  </tr>
                  <tr v-if="linkName !== '申请'">
                    <th>姓名</th>
                    <td v-if="linkName=='数据修订'" colspan="2">
                      <a-input
                        v-model="form.fxm"
                        class="">
                      </a-input>
                    </td>
                    <td v-else colspan="2">
                      {{ form.fxm }}
                    </td>
                    <th>职务</th>
                    <td v-if="linkName=='数据修订'" colspan="2">
                      <a-input
                        v-model="form.fzw"
                        class="">
                      </a-input></td>
                    <td v-else colspan="2">
                      {{ form.fzw }}
                    </td>
                  </tr>
                  <tr>
                    <th>加班/值班时间</th>
                    <td colspan="3" v-if="linkName == '申请'||linkName == '数据修订'">
                      <!-- <a-form-item prop="time">
                        <a-range-picker
                          :show-time="{ format: 'HH:mm' }"
                          format="YYYY-MM-DD HH:mm"
                          :placeholder="['加班/值班开始时间', '加班/值班结束时间']"
                          v-model="time"
                          @ok="onOk"
                          style="width: 400px;"
                          v-decorator="[
                            'time', {initialValue:time,rules: rules.time}
                          ]"
                        />
                      </a-form-item> -->
                      <a-form-model-item>
                            <a-input-group compact>
                                <a-date-picker
                                    style="width: 60%"
                                    type="date"
                                    placeholder="加班/值班开始日期"
                                    @change="date1Change"
                                    v-decorator="[ 'fjbzbksrq', {initialValue:form.fjbzbksrq,rules: rules.fjbzbksrq}]"/>
                                <a-select
                                    style="width: 40%"
                                    default-value="08:00"
                                    v-model="form.fjbzbkssj"
                                    placeholder="开始时间"
                                    @change="time1Change">
                                    <a-select-option value="08:00">
                                        08:00
                                    </a-select-option>
                                    <a-select-option value="12:00">
                                        12:00
                                    </a-select-option>
                                    <a-select-option value="18:00">
                                        18:00
                                    </a-select-option>
                                </a-select>
                            </a-input-group>
                            <a-input-group compact>
                                <a-date-picker
                                    style="width: 60%"
                                    type="date"
                                    placeholder="加班/值班结束日期"
                                    @change="date2Change"
                                    v-decorator="[ 'fjbzbjsrq', {initialValue:form.fjbzbjsrq,rules: rules.fjbzbjsrq}]"/>
                                    <a-select
                                        style="width: 40%;"
                                        default-value="18:00"
                                        placeholder="结束时间"
                                        v-model="form.fjbzbjssj"
                                        @change="time2Change">
                                        <a-select-option value="08:00">
                                            08:00
                                        </a-select-option>
                                        <a-select-option value="12:00">
                                            12:00
                                        </a-select-option>
                                        <a-select-option value="18:00">
                                            18:00
                                        </a-select-option>
                                    </a-select>
                            </a-input-group>
                        </a-form-model-item>
                    </td>
                    <td v-else colspan="3">
                      {{form.fjbzbksrq}} {{ form.fjbzbkssj }} 至 {{form.fjbzbjsrq}} {{ form.fjbzbjssj }}
                    </td>
                    <td style="width: 200px;" colspan="2">
                      共 {{ form.fjbzbsc }} 天
                    </td>
                  </tr>
                  <tr>
                    <th style="width:170px;">加班值班理由</th>
                    <td colspan="5" v-if="linkName == '申请'">
                      <a-form-item prop="fjbzbsy">
                            <a-textarea
                                v-model="form.fjbzbsy"
                                placeholder="请输入加班值班理由:"
                                :auto-size="{ minRows: 2}"
                                v-decorator="[ 'fjbzbsy', {initialValue:form.fjbzbsy,rules: rules.fjbzbsy}]" />
                          <!-- <a-textarea
                            placeholder="请输入加班值班理由"
                            auto-size
                            v-model:value="form.fjbzbsy"
                            style="height: 100%;max-height:100%;
                                font-weight: 600;font-size: 18px;color: black;
                                margin-bottom:0px;"
                            v-decorator="[ 'fjbzbsy', {initialValue:form.fjbzbsy,rules: rules.fjbzbsy}]">
                          </a-textarea> -->
                      </a-form-item>
                    </td>
                    <td colspan="5" v-else-if="linkName=='数据修订'" class="" style="max-width: 500px;">
                        <a-input
                                v-model="form.fjbzbsy"
                                placeholder="请输入加班值班理由:"
                                type="textarea"/>
                      <!-- <a-textarea
                        placeholder="请输入加班值班理由"
                        auto-size
                        v-model:value="form.fjbzbsy"
                        style="height: 63px;max-height: none;
                                font-weight: 600;font-size: 18px;color: black;
                                margin-bottom:0px;">
                      </a-textarea> -->
                    </td>
                    <td colspan="5" v-else class="" style="max-width: 500px;text-align: left;padding-left: 10px;">
                      {{form.fjbzbsy}}
                    </td>
                  </tr>
                  <tr>
                    <th >科室负责人意见</th>
                    <td v-if="linkName == '科室审批' || linkName == '数据修订'" colspan="5">
                        <a-form-model-item ref="fksspr" prop="fksspr">
                            <reviewOpinions
                                ref="reviewOpinionsRefKs"
                                @getInputOpinion="getInputOpinion"
                                @openOpinions="ksOpinions"
                                v-decorator="[
                                'fksspr', {initialValue:form.fksspr,rules: rules.fksspr}]"
                            />
                        </a-form-model-item>
                        <div v-if="linkName == '数据修订'" class="yjqm-right-bottom">
                            <a-input
                                @click="checkMan('fkssprqm',form.fkssprqm)"
                                v-model="form.fkssprqm"
                                class="checkMan-Xiu"
                                placeholder="指定科室待办人">
                            </a-input>
                            <a-date-picker
                                show-time
                                placeholder="科室负责人意见时间："
                                v-model="form.fkssprqmsj"
                                @change="timeChang($event,'fkssprqmsj')"
                                class="checkTime-Xiu"/>
                            </div>
                    </td>
                    <td v-else colspan="5">
                        <p class="text-align-left">{{ form.fksspr }}</p>
                        <div class="yjqm-right-bottom">
                            <img v-if="getUrl('科室审批') && form.fkssprqmsj" :src="getUrl('科室审批')" alt="" class="yjqmImg"/>
                            <span v-else class="yjqmImg">{{ form.fkssprqm }}</span>
                            <span>{{ form.fkssprqmsj }}</span>
                        </div>
                    </td>
                  </tr>
                  <tr>
                    <th >分管领导意见</th>
                    <td v-if="linkName == '分管审批' || linkName == '数据修订'" colspan="5">
                        <a-form-model-item ref="ffgspr" prop="ffgspr">
                            <reviewOpinions
                                ref="reviewOpinionsRefFg"
                                @getInputOpinion="getInputOpinion"
                                @openOpinions="fgOpinions"
                                v-decorator="[
                                'ffgspr', {initialValue:form.ffgspr,rules: rules.ffgspr}]"
                            />
                        </a-form-model-item>
                        <div v-if="linkName == '数据修订'" class="yjqm-right-bottom">
                            <a-input
                                @click="checkMan('ffgsprqm',form.ffgsprqm)"
                                v-model="form.ffgsprqm"
                                class="checkMan-Xiu"
                                placeholder="分管领导意见人：">
                            </a-input>
                            <a-date-picker
                                show-time
                                placeholder="分管领导意见时间："
                                v-model="form.ffgsprqmsj"
                                @change="timeChang($event,'ffgsprqmsj')"
                                class="checkTime-Xiu"/>
                            </div>
                    </td>
                    <td v-else colspan="5">
                        <p class="text-align-left">{{ form.ffgspr }}</p>
                        <div class="yjqm-right-bottom">
                            <img v-if="getUrl('分管审批') && form.ffgsprqmsj" :src="getUrl('分管审批')" alt="" class="yjqmImg"/>
                            <span v-else class="yjqmImg">{{ form.ffgsprqm }}</span>
                            <span>{{ form.ffgsprqmsj }}</span>
                        </div>
                    </td>
                  </tr>
                  <tr>
                    <th >单位领导意见</th>
                    <td v-if="linkName == '单位领导审批' || linkName == '数据修订'" colspan="5">
                        <a-form-model-item ref="fdwldspr" prop="fdwldspr">
                            <reviewOpinions
                                ref="reviewOpinionsRefZxld"
                                @getInputOpinion="getInputOpinion"
                                @openOpinions="zxldOpinions"
                                v-decorator="[
                                'fdwldspr', {initialValue:form.fdwldspr,rules: rules.fdwldspr}]"
                            />
                        </a-form-model-item>
                        <div v-if="linkName == '数据修订'" class="yjqm-right-bottom">
                            <a-input
                                @click="checkMan('fdwldsprqm',form.fdwldsprqm)"
                                v-model="form.fdwldsprqm"
                                class="checkMan-Xiu"
                                placeholder="中心领导意见人：">
                            </a-input>
                            <a-date-picker
                                show-time
                                placeholder="中心领导意见时间："
                                v-model="form.fdwldsprqmsj"
                                @change="timeChang($event,'fdwldsprqmsj')"
                                class="checkTime-Xiu"/>
                            </div>
                    </td>
                    <td v-else colspan="5">
                        <p class="text-align-left">{{ form.fdwldspr }}</p>
                        <div class="yjqm-right-bottom">
                            <img v-if="getUrl('单位领导审批') && form.fdwldsprqmsj" :src="getUrl('单位领导审批')" alt="" class="yjqmImg"/>
                            <span v-else class="yjqmImg">{{ form.fdwldsprqm }}</span>
                            <span>{{ form.fdwldsprqmsj }}</span>
                        </div>
                    </td>
                  </tr>
                  <tr v-if="linkName !== '加班办理'">
                    <th >加班/值班办理</th>
                    <td v-if="linkName == '数据修订'" colspan="5">
                        <a-input v-model="form.fjbzbblrqm" type="textarea">
                        </a-input>
                        <div class=" yjqm-right-bottom">
                            <a-input
                                v-model="form.fjbzbblrqm"
                                @click="checkMan('fjbzbblrqm',form.fjbzbblrqm)"
                                placeholder="加班/值班办理人："
                                class="checkMan-Xiu">
                            </a-input>
                            <a-date-picker
                                show-time
                                placeholder="加班/值班办理时间："
                                v-model="form.fjbzbblrqmsj"
                                @change="timeChang($event,'fjbzbblrqmsj')"
                                class="checkTime-Xiu"/>
                        </div>
                    </td>
                    <td v-else colspan="5">
                        <p class=" text-align-left">{{form.fjbzbblr}}</p>
                        <div class=" yjqm-right-bottom">
                            <img v-if="getUrl('加班办理') && form.fjbzbblrqmsj" :src="getUrl('加班办理')" alt="" class="yjqmImg"/>
                            <span v-else class="yjqmImg">{{ form.fjbzbblrqm }}</span>
                            <span>{{ form.fjbzbblrqmsj }}</span>
                        </div>
                    </td>
                    <!-- <td colspan="9">
                      <div style="line-height: 40px;">
                        <p v-if="form.fjbzbblrqmsj" class=" text-align-left">{{form.fjbzbblr}}</p>
                      </div>
                      <div class=" yjqm-right-bottom">
                        <a-input
                          v-if="linkName=='数据修订'"
                          v-model="form.fjbzbblrqm"
                          @click="checkMan('fjbzbblrqm',form.fjbzbblrqm)"
                          placeholder="加班/值班办理人："
                          class=""></a-input>
                        <span v-else>{{ form.fjbzbblrqm }}</span>
                        <br/>
                        <a-date-picker
                          v-if="linkName=='数据修订'"
                          show-time
                          placeholder="加班/值班办理时间："
                          v-model="form.fjbzbblrqmsj"
                          @change="timeChang($event,'fjbzbblrqmsj')"
                          class=""
                          style="width:220px;"/>
                        <span v-else>{{ form.fjbzbblrqmsj }}</span>
                      </div>
                    </td> -->
                  </tr>
                </table>
              </div>
            </a-tab-pane>
            <a-tab-pane v-if="linkName == '我的已办'" key="2" tab="流转记录">
              <a-table
                :columns="lzColumns"
                :data-source="lzList"
                bordered
                style="border-color: #d9d9d9;font-weight: 600;text-align: center;"
                :customRow="customRow">
              </a-table>
            </a-tab-pane>
            <a-button
                v-if="showPrintBtn(linkName,form.flczt,tabsKey)"
              slot="tabBarExtraContent"
              v-print="printObj"
              class="print-btn">
              打印
            </a-button>
          </a-tabs>
        </a-form>
      </a-modal>
      <personnelList ref="personnelListRef" :modaObj="modaObj" @checkPersonnel="checkPersonnel"></personnelList>
    </div>
  </template>
  <script>
  import personnelList from '../../modal/personnelList'
  import {initBzFlow,saveFlow,submitFlow,flowJkPage,downMyQm,jbzbEdit,queryAllYbJob,returnUpperzdyFlowJob} from './service/index'
  import moment from 'moment'
  export default {
    props:{
      formData:{
        type:[Array,Object],
        default: () => {},
        required:false
      },
      linkName:{
        type:String,
        default:'',
        required:false,
      },
    //   stepNums:{
    //     type:Number,
    //     default: '',
    //     require:false,
    //   },
    },
    components: {
      personnelList
    },
    data() {
      return {
        loading: false,
        applicationFormVisible: false,
        showFooter: false,
        cform:this.$form.createForm(this, { name: 'cform' }),
        tabsKey: '1',
        form: {
          id: '',
          oaid: '',
          jobid: '',
          fbm: '',
          fjbzbsqrq: '',
          fxm: '',
          fzw: '',
          flglx: '',
          fjbzbsy: '',
          fjbzbkssj: '08:00',
          fjbzbjssj: '18:00',
          fjbzbksrq: null,
          fjbzbjsrq: null,

          createBy: "",
          createTime: "",
          fbz: "",
          ffgldqm: "",
          ffgsprqmsj: "",
          ffgldyj: "",
          fkssprqm: "",
          fkssprqmsj: "",
          fksspr: "",
          flczt: "",
          fjbzbsc: '',
          fsffqlc: "",
          fuserid: "",
          fjbzbblrqm: "",
          fjbzbblrqmsj: "",

          fdbr: '',
          fdbrid: '',
        },
        kongForm: {},
        moment,
        modaObj: {},
        rules:{
          fjbzbsy: [{
                required: true,
                message: '请填写加班值班理由',
                trigger: 'blur',
            }],
          fjbzbksrq: [{
                type: 'object',
                required: true,
                message: '请填写加班/值班开始日期',
                trigger: 'blur',
            }],
            fjbzbjsrq: [{
                type: 'object',
                required: true,
                message: '请填写加班/值班结束日期',
                trigger: 'blur',
            }],
          time: [{
              type: 'array',
              required: true,
              message: '请选择加班/值班时间',
              trigger: 'blur',
          }],
          fksspr: [{
              required: true,
              message: '请填写科室负责人意见',
              trigger: 'blur',
          }],
          ffgspr: [{
              required: true,
              message: '请填写分管领导意见',
              trigger: 'blur',
          }],
          fdwldspr: [{
              required: true,
              message: '请填写中心领导意见',
              trigger: 'blur',
          }],
        },
        time: '',

        // tag-2
        lzColumns: [
          {
            title: '环节名称',
            dataIndex: 'fhjmc',
            key: 'fhjmc',
            width: 150,
          },{
            title: '待办人',
            dataIndex: 'fdbr',
            key: 'fdbr',
            width: 100,
          },{
            title: '办理人',
            dataIndex: 'fblr',
            key: 'fblr',
            width: 100,
          },{
            title: '发送时间',
            dataIndex: 'ffssj',
            key: 'ffssj',
            width: 170,
          },{
            title: '办理时间',
            dataIndex: 'fblsj',
            key: 'fblsj',
            width: 170,
          },{
            title: '办理状态',
            dataIndex: 'fblzt',
            key: 'fblzt',
            width: 100,
          },{
            title: '办理类型',
            dataIndex: 'fbllx',
            key: 'fbllx',
            width: 300,
          },{
            title: '办理意见',
            dataIndex: 'fblyj',
            key: 'fblyj',
          },
        ],
        lzList: [],
        imgList: [
          {fhjmc:'科室审批',url: ''},
          {fhjmc:'分管审批',url: ''},
          {fhjmc:'单位领导审批',url: ''},
          {fhjmc:'加班办理',url: ''},
        ],
        // 打印
        printObj:{
          id:"printTest", //需要打印的id名称
          popTitle:"干部职工加班值班登记表",//文档的名称
          // preview:true,//预览功能，不好用
          zIndex:'20002',
          beforeOpenCallback(vue){},
          openCallback (vue) {
            //打开之前
          },
          closeCallback (vue) {
            //关闭了打印工具
          },
        },
      }
    },
    mounted(){
      this.kongForm = JSON.parse(JSON.stringify(this.form))
    },
    watch: {
      formData(newval,oldVal){
        // //console.log('stepNums',this.stepNums)
        this.form = {...newval}
        // this.time = [this.form.fjbzbkssj,this.form.fjbzbjssj]
        if(this.linkName == '申请'){
            this.form.fjbzbksrq = this.form.fjbzbksrq ? moment(this.form.fjbzbksrq):''
            this.form.fjbzbjsrq = this.form.fjbzbjsrq ? moment(this.form.fjbzbjsrq):''
        }
        //console.log('applicationForm',this.form)
        let id = this.form.oaid
        this.getflowJkPage(id)
        if(this.linkName == '流程监控'||this.linkName == '我的已办'||this.linkName == '加班办理'||this.linkName=='数据修订'){
          this.showFooter = true
        }
      }
    },
    methods: {
        showPrintBtn(linkName,flczt,tabsKey){
            if(linkName == '我的已办' && flczt == '流程结束' && tabsKey == '1'){
                return true
            } else {
                return false
            }
        },
      closeVisible(){
        this.applicationFormVisible = false
        this.$emit('success')
        this.form = {...this.kongForm}
        this.time = ''
      },
      callback(key) {
        this.tabsKey = key
      },
      date1Change(val){
        this.form.fjbzbksrq = val==null?null:moment(val).format('YYYY-MM-DD')
        this.timeChange()
        },
        date2Change(val){
        this.form.fjbzbjsrq = val==null?null:moment(val).format('YYYY-MM-DD')
        this.timeChange()
        },
      time1Change(val){
        this.timeChange()
        },
        time2Change(val){
        this.timeChange()
        },
        timeChange(){
            //console.log('=============',this.form.fjbzbksrq,this.form.fjbzbjsrq)
        if(this.form.fjbzbksrq !== null && this.form.fjbzbjsrq !==null){
            let start = new Date(Date.parse(this.form.fjbzbksrq));
            let end = new Date(Date.parse(this.form.fjbzbjsrq));
            let diff = end.getTime() - start.getTime();// 两个日期相差的毫秒数
            let days = Math.floor(diff / (1000 * 60 * 60 * 24))
            let time1 = Number(this.form.fjbzbkssj.substr(0,2))
            let time2 = Number(this.form.fjbzbjssj.substr(0,2))
            let time3 = time1 + time2
            let time = 0
            if(days == 0){
                if(this.form.fjbzbkssj == '08:00'){
                    if(this.form.fjbzbjssj == '08:00'){
                    this.$message.warning('当前选择天数为0，请重新选择！')
                    } else if(this.form.fjbzbjssj == '12:00'){
                    time = 0.5
                    } else if(this.form.fjbzbjssj == '18:00'){
                    time = 1
                    }
                } else if(this.form.fjbzbkssj == '12:00'){
                    if(this.form.fjbzbjssj == '08:00'){
                    this.$message.warning('当前选择天数为0，请重新选择！')
                    } else if(this.form.fjbzbjssj == '12:00'){
                    time = 0
                    } else if(this.form.fjbzbjssj == '18:00'){
                    time = 0.5
                    }
                } else if(this.form.fjbzbkssj == '18:00'){
                    if(this.form.fjbzbjssj == '08:00'){
                    this.$message.warning('当前选择天数为0，请重新选择！')
                    } else if(this.form.fjbzbjssj == '12:00'){
                    this.$message.warning('当前选择天数为0，请重新选择！')
                    } else if(this.form.fjbzbjssj == '18:00'){
                    time = 0
                    }
                }
            } else {
                if(this.form.fjbzbkssj == '08:00'){
                    if(this.form.fjbzbjssj == '08:00'){
                    time = 0
                    } else if(this.form.fjbzbjssj == '12:00'){
                    time = 0.5
                    } else if(this.form.fjbzbjssj == '18:00'){
                    time = 1
                    }
                } else if(this.form.fjbzbkssj == '12:00'){
                    if(this.form.fjbzbjssj == '08:00'){
                    time = -0.5
                    } else if(this.form.fjbzbjssj == '12:00'){
                    time = 0
                    } else if(this.form.fjbzbjssj == '18:00'){
                    time = 0.5
                    }
                } else if(this.form.fjbzbkssj == '18:00'){
                    if(this.form.fjbzbjssj == '08:00'){
                    if(days == 1){
                        this.$message.warning('当前选择天数为0，请重新选择！')
                        time = -1
                    } else {
                        time = 0
                    }
                    } else if(this.form.fjbzbjssj == '12:00'){
                    if(days == 1){
                        time = -0.5
                    } else {
                        time = 0
                    }
                    } else if(this.form.fjbzbjssj == '18:00'){
                    time = 0
                    }
                }
            }
            let data = days + time
            if(data <= 0){
              this.$message.warning('加班值班天数需大于0，当前选择天数为'+data+'天，请重新选择')
              this.form.fjbzbsc = ''
              return
            }
            this.form.fjbzbsc = data
            //console.log(this.form.fjbzbsc)
        } else {
            this.form.fjbzbsc = ''
        }
        },
      // 加班/值班时间
      onChange(value, dateString) {
        //console.log('Selected Time: ', value);
        //console.log('Formatted Selected Time: ', dateString);
        this.form.fjbzbkssj = dateString[0]
        this.form.fjbzbjssj = dateString[1]
      },
      onOk(value) {
        // //console.log('onOk: ', value);
        this.cform.setFieldsValue({
          fjbzbkssj : moment(value[0]).format('YYYY-MM-DD HH:mm'),
          fjbzbjssj : moment(value[1]).format('YYYY-MM-DD HH:mm')
        })
        this.form.fjbzbkssj = moment(value[0]).format('YYYY-MM-DD HH:mm')
        this.form.fjbzbjssj = moment(value[1]).format('YYYY-MM-DD HH:mm')

        let start = new Date(Date.parse(this.form.fjbzbkssj));
        let end = new Date(Date.parse(this.form.fjbzbjssj));
        let diff = end.getTime() - start.getTime(); // 两个日期相差的毫秒数
        // let diffDays = Math.floor(diff / (24 * 60 * 60 * 1000)); // 相差的天数
        // let diffHours = Math.floor(diff / (60 * 60 * 1000)); // 相差的小时数
        // let diffMinutes = Math.floor(diff / (60 * 1000)); // 相差的分钟数
        // //console.log(diffMinutes+'分')
        // let DD = Math.trunc(diffMinutes/1440)
        // let HH = Math.trunc(diffMinutes/60) //仅保留整数部分
        // let mm = diffMinutes%60
        // //console.log(HH,mm)
        let days = Math.floor(diff / (1000 * 60 * 60 * 24))
        let hours = Math.floor((diff % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60))
        let minutes = Math.floor((diff % (1000 * 60 * 60)) / (1000 * 60))
        let seconds = Math.round((diff % (1000 * 60)) / 1000)
        if(days == 0){
          this.form.fjbzbsc = hours + "小时" + minutes + "分钟"
        } else {
          this.form.fjbzbsc = days + "天" + hours + "小时" + minutes + "分钟"
        }
      },
      timeChang(val,name){
        let data = this.form
        if(name == 'ffbrq'){
          data[name] = moment(val).format('YYYY-MM-DD')
        } else {
          data[name] = moment(val).format('YYYY-MM-DD HH:mm:ss')
        }
      },
      // 加班/值班开始时间
      flgsjChange(val){
        this.form.fjbzbkssj = moment(val).format('YYYY-MM-DD HH:mm:ss')
        // var stime = Date.parse(new Date(this.form.fjbzbkssj));
        if(this.form.fjbzbsc !== 0){
          var haomiao = this.form.fjbzbsc * 3600000
          var stime = Date.parse(new Date(this.form.fjbzbkssj));
          var ztime = Number(stime) + Number(haomiao)
          var htime = new Date(ztime)

          this.form.fjbzbjssj = moment(htime).format('YYYY-MM-DD HH:mm:ss')
          // //console.log(this.form.fjbzbjssj)
        }
      },
      // 选择加班/值班开始小时数
      handleChange(value) {
        if(this.form.fjbzbkssj !== ''){
          var haomiao = value * 3600000
          var stime = Date.parse(new Date(this.form.fjbzbkssj));
          var ztime = Number(stime) + Number(haomiao)
          var htime = new Date(ztime)
          // //console.log()

          this.form.fjbzbjssj = moment(htime).format('YYYY-MM-DD HH:mm:ss')
          //console.log(this.form.fjbzbjssj)
        }
      },
      reviewRecordsFocusEvent(){},
      // 保存+提交
      saveTable(str){
        let data = {}
        //console.log( this.form)
        if(this.linkName == '申请'){
          if(this.form.id){
            data = {
              jobid: this.form.jobid,
              oaid: this.form.id,
              lcmbCode: '',
                nextNodeId: '',
                nextNode: '',
                currentNode: '',
                dbrid: '',
                smgflag: '',
              map: {
                id: this.form.id,
                fbm: this.form.fbm,
                fjbzbsqrq: this.form.fjbzbsqrq,
                fxm: this.form.fxm,
                fzw: this.form.fzw,
                fjbzbsy: this.form.fjbzbsy,
                fjbzbksrq: moment(this.form.fjbzbksrq).format('YYYY-MM-DD'),
                fjbzbjsrq: moment(this.form.fjbzbjsrq).format('YYYY-MM-DD'),
                fjbzbkssj: this.form.fjbzbkssj,
                fjbzbjssj: this.form.fjbzbjssj,
                fjbzbsc: this.form.fjbzbsc
              },
            }
            if(str == '保存'){
              saveFlow(data).then(res => {
                // //console.log(res)
                if(res.code == 200){
                  this.$message.success(res.message)
                } else {
                  this.$message.warning(res.message)
                }
              })
            } else if(str == '提交') {
              this.loading = true
              submitFlow(data).then(res => {
                // //console.log(res)
                if(res.code == 200){
                  this.$message.success(res.message)
                  this.closeVisible()
                } else {
                  this.$message.warning(res.message)
                }
                this.loading = false
              })
            }
          } else {
            data = {
              id: this.form.id,
              fbm: this.form.fbm,
              fjbzbsqrq: this.form.fjbzbsqrq,
              fxm: this.form.fxm,
              fzw: this.form.fzw,
              fjbzbsy: this.form.fjbzbsy,
              fjbzbksrq: moment(this.form.fjbzbksrq).format('YYYY-MM-DD'),
                fjbzbjsrq: moment(this.form.fjbzbjsrq).format('YYYY-MM-DD'),
              fjbzbkssj: this.form.fjbzbkssj,
              fjbzbjssj: this.form.fjbzbjssj,
              fjbzbsc: this.form.fjbzbsc
            }
            if(str == '提交'){
              data = {
                ...data,
                fsffqlc: '是'
              }
              this.loading = true
            }
            // //console.log('data',data)
            initBzFlow(data).then(res => {
              // //console.log('保存',res)
              if(res.code == 200){
                this.$message.success(res.message)
                if(str == '提交'){
                  this.closeVisible()
                } else {
                  this.form = {
                    ...res.result.oaMap,
                    jobid: res.result.jobMap.id
                  }
                  this.form.id = res.result.oaMap.id//赋值
                }
              } else {
                this.$message.warning(res.message)
              }
              this.loading = false
            })
          }
        } else if(this.linkName == '科室审批'){
          data = {
            jobid: this.formData.jobid,
            oaid: this.formData.oaid,
            lcmbCode: '',
            nextNodeId: '',
            nextNode: '',
            currentNode: '',
            dbrid: '',
            smgflag: '',
            map: {
              fkssprqm: this.form.fkssprqm,
              fkssprqmsj: this.form.fkssprqmsj,
              fksspr: this.form.fksspr,
            },
            opinion: this.form.fksspr,
          }
          //console.log(data)

          if(str == '保存'){
            saveFlow(data).then(res => {
              // //console.log(res)
              if(res.code == 200){
                this.$message.success(res.message)
              } else {
                this.$message.warning(res.message)
              }
            })
          } else if(str == '提交') {
            submitFlow(data).then(res => {
              // //console.log(res)
              if(res.code == 200){
                this.$message.success(res.message)
                this.closeVisible()
              } else {
                this.$message.warning(res.message)
              }
            })
          }
        } else if(this.linkName == '分管审批'){
          data = {
            jobid: this.formData.jobid,
            oaid: this.formData.oaid,
            lcmbCode: '',
            nextNodeId: '',
            nextNode: '',
            currentNode: '',
            dbrid: '',
            smgflag: '',
            map: {
              ffgspr: this.form.ffgspr,
              ffgsprqm: this.form.ffgsprqm,
              ffgsprqmsj: this.form.ffgsprqmsj,
            },
            opinion: this.form.ffgspr,
          }

          if(str == '保存'){
            saveFlow(data).then(res => {
              // //console.log(res)
              if(res.code == 200){
                this.$message.success(res.message)
              } else {
                this.$message.warning(res.message)
              }
            })
          } else if(str == '提交') {
            submitFlow(data).then(res => {
              // //console.log(res)
              if(res.code == 200){
                this.$message.success(res.message)
                this.closeVisible()
              } else {
                this.$message.warning(res.message)
              }
            })
          }
        } else if(this.linkName == '单位领导审批'){
          data = {
            jobid: this.formData.jobid,
            oaid: this.formData.oaid,
            lcmbCode: '',
            nextNodeId: '',
            nextNode: '',
            currentNode: '',
            dbrid: '',
            smgflag: '',
            map: {
              fdwldspr: this.form.fdwldspr,
              fdwldsprqm: this.form.fdwldsprqm,
              fdwldsprqmsj: this.form.fdwldsprqmsj,
            },
            opinion: this.form.fdwldspr,
          }

          if(str == '保存'){
            saveFlow(data).then(res => {
              // //console.log(res)
              if(res.code == 200){
                this.$message.success(res.message)
              } else {
                this.$message.warning(res.message)
              }
            })
          } else if(str == '提交') {
            submitFlow(data).then(res => {
              // //console.log(res)
              if(res.code == 200){
                this.$message.success(res.message)
                this.closeVisible()
              } else {
                this.$message.warning(res.message)
              }
            })
          }
        } else if(this.linkName == '加班办理') {
          data = {
            jobid: this.formData.jobid,
            oaid: this.formData.oaid,
            lcmbCode: '',
            nextNodeId: '',
            nextNode: '',
            currentNode: '',
            dbrid: '',
            smgflag: '',
            map: {
              fjbzbblr: '确认加班值班',
              fjbzbblrqm: this.form.fjbzbblrqm,
              fjbzbblrqmsj: this.form.fjbzbblrqmsj,
            },
            opinion: '确认加班值班',
          }
            submitFlow(data).then(res => {
              // //console.log(res)
              if(res.code == 200){
                this.$message.success(res.message)
                this.closeVisible()
              } else {
                this.$message.warning(res.message)
              }
            })
          // }
        }
      },
        subTable(str){
            this.cform.validateFields((err, values) => {
                //console.log(err)
                //console.log(values)
                if (!err) {
                    var that = this
                    that.$confirm({
                        title: '您确定要提交吗?',
                        onOk() {
                            //console.log(values)
                            let data = {}
                            //console.log( that.form)
                            if(that.linkName == '申请'){
                                if(that.form.id){
                                    data = {
                                    jobid: that.form.jobid,
                                    oaid: that.form.id,
                                    lcmbCode: '',
                                        nextNodeId: '',
                                        nextNode: '',
                                        currentNode: '',
                                        dbrid: '',
                                        smgflag: '',
                                    map: {
                                        id: that.form.id,
                                        fbm: that.form.fbm,
                                        fjbzbsqrq: that.form.fjbzbsqrq,
                                        fxm: that.form.fxm,
                                        fzw: that.form.fzw,
                                        fjbzbsy: that.form.fjbzbsy,
                                        fjbzbksrq: moment(that.form.fjbzbksrq).format('YYYY-MM-DD'),
                                        fjbzbjsrq: moment(that.form.fjbzbjsrq).format('YYYY-MM-DD'),
                                        fjbzbkssj: that.form.fjbzbkssj,
                                        fjbzbjssj: that.form.fjbzbjssj,
                                        fjbzbsc: that.form.fjbzbsc
                                    },
                                    }
                                    if(str == '保存'){
                                    saveFlow(data).then(res => {
                                        // //console.log(res)
                                        if(res.code == 200){
                                        that.$message.success(res.message)
                                        } else {
                                        that.$message.warning(res.message)
                                        }
                                    })
                                    } else if(str == '提交') {
                                    that.loading = true
                                    submitFlow(data).then(res => {
                                        // //console.log(res)
                                        if(res.code == 200){
                                        that.$message.success(res.message)
                                        that.closeVisible()
                                        } else {
                                        that.$message.warning(res.message)
                                        }
                                        that.loading = false
                                    })
                                    }
                                } else {
                                    data = {
                                    id: that.form.id,
                                    fbm: that.form.fbm,
                                    fjbzbsqrq: that.form.fjbzbsqrq,
                                    fxm: that.form.fxm,
                                    fzw: that.form.fzw,
                                    fjbzbsy: that.form.fjbzbsy,
                                    fjbzbksrq: moment(that.form.fjbzbksrq).format('YYYY-MM-DD'),
                                        fjbzbjsrq: moment(that.form.fjbzbjsrq).format('YYYY-MM-DD'),
                                    fjbzbkssj: that.form.fjbzbkssj,
                                    fjbzbjssj: that.form.fjbzbjssj,
                                    fjbzbsc: that.form.fjbzbsc
                                    }
                                    if(str == '提交'){
                                    data = {
                                        ...data,
                                        fsffqlc: '是'
                                    }
                                    that.loading = true
                                    }
                                    // //console.log('data',data)
                                    initBzFlow(data).then(res => {
                                    // //console.log('保存',res)
                                    if(res.code == 200){
                                        that.$message.success(res.message)
                                        if(str == '提交'){
                                        that.closeVisible()
                                        } else {
                                        that.form = {
                                            ...res.result.oaMap,
                                            jobid: res.result.jobMap.id
                                        }
                                        that.form.id = res.result.oaMap.id//赋值
                                        }
                                    } else {
                                        that.$message.warning(res.message)
                                    }
                                    that.loading = false
                                    })
                                }
                            } else if(that.linkName == '科室审批'){
                            data = {
                                jobid: that.formData.jobid,
                                oaid: that.formData.oaid,
                                lcmbCode: '',
                                nextNodeId: '',
                                nextNode: '',
                                currentNode: '',
                                dbrid: '',
                                smgflag: '',
                                map: {
                                fkssprqm: that.form.fkssprqm,
                                fkssprqmsj: that.form.fkssprqmsj,
                                fksspr: that.form.fksspr,
                                },
                                opinion: that.form.fksspr,
                            }
                            //console.log(data)

                            if(str == '保存'){
                                saveFlow(data).then(res => {
                                // //console.log(res)
                                if(res.code == 200){
                                    that.$message.success(res.message)
                                } else {
                                    that.$message.warning(res.message)
                                }
                                })
                            } else if(str == '提交') {
                                submitFlow(data).then(res => {
                                // //console.log(res)
                                if(res.code == 200){
                                    that.$message.success(res.message)
                                    that.closeVisible()
                                } else {
                                    that.$message.warning(res.message)
                                }
                                })
                            }
                            } else if(that.linkName == '分管审批'){
                                data = {
                                    jobid: that.formData.jobid,
                                    oaid: that.formData.oaid,
                                    lcmbCode: '',
                                    nextNodeId: '',
                                    nextNode: '',
                                    currentNode: '',
                                    dbrid: '',
                                    smgflag: '',
                                    map: {
                                    ffgspr: that.form.ffgspr,
                                    ffgsprqm: that.form.ffgsprqm,
                                    ffgsprqmsj: that.form.ffgsprqmsj,
                                    },
                                    opinion: that.form.ffgspr,
                                }

                            if(str == '保存'){
                                saveFlow(data).then(res => {
                                // //console.log(res)
                                if(res.code == 200){
                                    that.$message.success(res.message)
                                } else {
                                    that.$message.warning(res.message)
                                }
                                })
                            } else if(str == '提交') {
                                submitFlow(data).then(res => {
                                // //console.log(res)
                                if(res.code == 200){
                                    that.$message.success(res.message)
                                    that.closeVisible()
                                } else {
                                    that.$message.warning(res.message)
                                }
                                })
                            }
                            } else if(that.linkName == '单位领导审批'){
                            data = {
                                jobid: that.formData.jobid,
                                oaid: that.formData.oaid,
                                lcmbCode: '',
                                nextNodeId: '',
                                nextNode: '',
                                currentNode: '',
                                dbrid: '',
                                smgflag: '',
                                map: {
                                fdwldspr: that.form.fdwldspr,
                                fdwldsprqm: that.form.fdwldsprqm,
                                fdwldsprqmsj: that.form.fdwldsprqmsj,
                                },
                                opinion: that.form.fdwldspr,
                            }

                            if(str == '保存'){
                                saveFlow(data).then(res => {
                                // //console.log(res)
                                if(res.code == 200){
                                    that.$message.success(res.message)
                                } else {
                                    that.$message.warning(res.message)
                                }
                                })
                            } else if(str == '提交') {
                                submitFlow(data).then(res => {
                                // //console.log(res)
                                if(res.code == 200){
                                    that.$message.success(res.message)
                                    that.closeVisible()
                                } else {
                                    that.$message.warning(res.message)
                                }
                                })
                            }
                            } else if(that.linkName == '加班办理') {
                            data = {
                                jobid: that.formData.jobid,
                                oaid: that.formData.oaid,
                                lcmbCode: '',
                                nextNodeId: '',
                                nextNode: '',
                                currentNode: '',
                                dbrid: '',
                                smgflag: '',
                                map: {
                                fjbzbblr: '确认加班值班',
                                fjbzbblrqm: that.form.fjbzbblrqm,
                                fjbzbblrqmsj: that.form.fjbzbblrqmsj,
                                },
                                opinion: '确认加班值班',
                            }
                                submitFlow(data).then(res => {
                                // //console.log(res)
                                if(res.code == 200){
                                    that.$message.success(res.message)
                                    that.closeVisible()
                                } else {
                                    that.$message.warning(res.message)
                                }
                                })
                            // }
                            }
                        },
                        onCancel() {},
                    });
                }
            })
        },
      //流转记录
      getflowJkPage(id){
        flowJkPage({oaid:id}).then(res => {
          let arr1 = []
                arr1 = res.result.records
          // var arr1 = [1, 2, 3, 4, 5, 6, 7];
          var arr2 = new Array();
          for (let i = arr1.length - 1; i >= 0; i--) {
            arr2.push(arr1[i]);
          }
          // //console.log('arr2',arr2)
          this.lzList = []
          arr1.forEach(item => {
            item = {
              ...item,
              key: item.jobid
            }
            this.lzList.push(item)
            this.imgList.forEach((items,a)=> {
              if(item.fdbrid){
                if(items.fhjmc == item.fhjmc){
                  downMyQm({id:item.fdbrid}).then(resa => {
                    if(resa.code){
                      this.imgList[a].url = null
                    } else {
                      this.imgList[a].url = "data:image/png;base64," +
                      btoa( new Uint8Array(resa).reduce( (data, byte) => data + String.fromCharCode(byte), "" ))
                    }
                  })
                }
              } else {}
            })
            //console.log('imgList',this.imgList)
          })
        })
      },
      customRow() {
        return {
          style: {
              'font-size' : '16px',
              'text-align' : 'center'
          },
        }
      },
      getUrl(ids){
        let url = ''
        this.imgList.forEach(item => {
          if(item.fhjmc == ids){
            url = item.url
          }
        })
        // //console.log('长度',url.length)
        return url
      },
      // 打开意见弹窗
      ksOpinions(){
          this.$refs.reviewOpinionsRefKs.getData({opinionType:'ksIdeaType',oldVal:this.form.fksspr,valueData:{hjmc:'fksspr'}})
      },
      fgOpinions(){
          this.$refs.reviewOpinionsRefFg.getData({opinionType:'fgIdeaType',oldVal:this.form.ffgspr,valueData:{hjmc:'ffgspr'}})
      },
      zxldOpinions(){
          this.$refs.reviewOpinionsRefZxld.getData({opinionType:'zxldIdeaType',oldVal:this.form.fdwldspr,valueData:{hjmc:'fdwldspr'}})
      },
      // 意见弹窗
      getInputOpinion(val,valueData){
        let data = this.form
        data[valueData.hjmc] = val
        this.cform.setFieldsValue({
          fjbzbsy: this.form.fjbzbsy,
          fksspr:this.form.fksspr,
          ffgspr: this.form.ffgspr,
          fdwldspr: this.form.fdwldspr,
        });
      },
      // 打开选择人员弹窗
      checkMan(place,man){
        this.$nextTick(_ => {
          this.modaObj = {place: place,manList: man}
          this.$refs.personnelListRef.personnelListVisible = true
              })
      },
      // 选择人员
      checkPersonnel(place,id,name){
        this.$refs.personnelListRef.personnelListVisible = false
        //console.log('-------------------')
        const data = this.form
        data[place] = name.toString()
        // data[fdbrid] = id.toString()
        // data[fdbr] = name.toString()
        // let Data = {
        //   jobid: this.form.jobid,
        //   fdbrid: id.toString(),
        //   fdbr: name.toString()
        // }
        // zddbrFlows(Data).then(res => {
        //   //console.log(res)
        // })
      },
      editTable(){
        let data = {
          id: this.form.id,
          fbm: this.form.fbm,
          fjbzbsqrq: this.form.fjbzbsqrq,
          fxm: this.form.fxm,
          fzw: this.form.fzw,
          fjbzbsy: this.form.fjbzbsy,
          fjbzbksrq: moment(this.form.fjbzbksrq).format('YYYY-MM-DD'),
            fjbzbjsrq: moment(this.form.fjbzbjsrq).format('YYYY-MM-DD'),
          fjbzbkssj: this.form.fjbzbkssj,
          fjbzbjssj: this.form.fjbzbjssj,
          ffgldqm: this.form.ffgldqm,
          ffgsprqmsj: this.form.ffgsprqmsj,
          ffgldyj: this.form.ffgldyj,
          fkssprqm: this.form.fkssprqm,
          fkssprqmsj: this.form.fkssprqmsj,
          fksspr: this.form.fksspr,
          fjbzbsc: this.form.fjbzbsc,
          fsffqlc: this.form.fsffqlc,
          fjbzbblrqm: this.form.fjbzbblrqm,
          fjbzbblrqmsj: this.form.fjbzbblrqmsj,
        }
        jbzbEdit(data).then(res => {
          if(res.code == 200){
            this.$message.success(res.message)
          } else {
            this.$message.warning(res.message)
          }
        })
      },
        // 退回意见
        returnClick(){
            this.cform.validateFields((err, values) => {
                if (!err) {
                    queryAllYbJob({jobid:this.form.jobid}).then(res => {
                        let list = res.result
                        list.forEach(item => {
                            if(item.fhjmc == '申请'){
                                this.returnFuntion(this.form.jobid,item.id)
                            }
                        })
                    })
                }
            })
        },
        returnFuntion(jobid,ids){
            let returnStr = ''
            if(this.linkName == '科室审批'){
                returnStr = this.form.fksspr
            } else if(this.linkName == '分管审批'){
                returnStr = this.form.ffgspr
            } else if(this.linkName == '单位领导审批'){
                returnStr = this.form.fdwldspr
            }
            let data = {
                jobid: jobid,
                opinion: returnStr,
                shjid: ids,
                smgflag: '',
                smsContent: '',
            }
            returnUpperzdyFlowJob(data).then(res => {
                if(res.code == 200){
                    this.$message.success(res.message)
                    this.closeVisible()
                } else {
                    this.$message.warning(res.message)
                }
            })
        },
    },
  }
  </script>
<style>
@import url('../../css/oaLess.css');
@import url('../../css/oaClass.css');
</style>
